package Panels;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import DatabaseCommands.Connect;
import DatabaseCommands.DatabaseInfo;


public class WithSSH extends JPanel implements ActionListener{
	
	DatabaseInfo DInfo=DatabaseInfo.getInstance();
	List<JLabel> Labels=new ArrayList<JLabel>();
	List<JTextField> TextFields=new ArrayList<JTextField>();
	private JPasswordField SSHPassword;
	private JPasswordField DatabasePassword;
	
	public WithSSH(){
		setLayout(new GridBagLayout());
		GridBagConstraints Constraints=new GridBagConstraints();
		
		Labels.add(new JLabel("Connecting with SSH"));
		Labels.get(0).setFont(new Font("Serif",Font.BOLD,20));
		Constraints.gridwidth=2;
		Constraints.gridx=0;
		add(Labels.get(0),Constraints);
		
		
		Labels.add(new JLabel("Local Port:  "));	
		Constraints.anchor=GridBagConstraints.EAST;
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(1),Constraints);
		
		TextFields.add(new JTextField("1234",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(0),Constraints);
		
		
		Labels.add(new JLabel("SSH Address:  "));	
		Constraints.anchor=GridBagConstraints.EAST;
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(2),Constraints);
		
		TextFields.add(new JTextField("sloop.cs.ship.edu",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(1),Constraints);
		
		
		Labels.add(new JLabel("SSH Port:  "));	
		Constraints.anchor=GridBagConstraints.EAST;
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(3),Constraints);
		
		TextFields.add(new JTextField("22",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(2),Constraints);
		
		
		Labels.add(new JLabel("SSH Username:  "));
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(4),Constraints);
		
		TextFields.add(new JTextField("es7976",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(3),Constraints);
		
		
		Labels.add(new JLabel("SSH Password:  "));
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(5),Constraints);
		
		SSHPassword=new JPasswordField("ambralfb",10);
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(SSHPassword,Constraints);
		
		
		Labels.add(new JLabel("Database address:  "));	
		Constraints.anchor=GridBagConstraints.EAST;
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(6),Constraints);
		
		TextFields.add(new JTextField("db.cs.ship.edu",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(4),Constraints);
		
		
		Labels.add(new JLabel("Database Port:  "));	
		Constraints.anchor=GridBagConstraints.EAST;
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(7),Constraints);
		
		TextFields.add(new JTextField("3306",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(5),Constraints);
		
		
		Labels.add(new JLabel("Database:  "));
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(8),Constraints);
		
		TextFields.add(new JTextField("csc371-10",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(6),Constraints);

		
		Labels.add(new JLabel("Database Username:  "));
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(9),Constraints);
		
		TextFields.add(new JTextField("csc371-10",10));
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(TextFields.get(7),Constraints);
		
		
		Labels.add(new JLabel("Database Password:  "));
		Constraints.gridwidth=1;
		Constraints.gridx=0;
		add(Labels.get(10),Constraints);
		
		DatabasePassword=new JPasswordField("Password10",10);
		Constraints.gridwidth=1;
		Constraints.gridx=1;
		add(DatabasePassword,Constraints);
		
		
		JButton SubmitButton=new JButton("Connect");
		SubmitButton.setFont(new Font("Serif",Font.PLAIN,16));
		SubmitButton.addActionListener(this);
		Constraints.anchor=GridBagConstraints.CENTER;
		Constraints.gridwidth=2;
		Constraints.gridx=0;
		add(SubmitButton,Constraints);
		
	}
	

	@Override
	public void actionPerformed(ActionEvent e){
		DInfo.SetInfo(TextFields.get(6).getText(),"localhost",TextFields.get(7).getText(),new String(DatabasePassword.getPassword()),new Integer(TextFields.get(0).getText()));
		new Connect(TextFields.get(1).getText(),TextFields.get(4).getText(),TextFields.get(3).getText(),new String(SSHPassword.getPassword()),new Integer(TextFields.get(2).getText()),new Integer(TextFields.get(0).getText()),new Integer(TextFields.get(5).getText()));		
	}
	
	
	

}
